/*
 *
 *      Copyright (c) 2018-2025, bpm All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: bpm
 *
 */

package com.yuandian.bpm.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.bpm.admin.api.entity.SysDict;
import com.yuandian.bpm.admin.api.entity.SysDictItem;
import com.yuandian.bpm.admin.service.SysDictItemService;
import com.yuandian.bpm.admin.service.SysDictService;
import com.yuandian.bpm.common.core.constant.CacheConstants;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.bpm.common.security.annotation.Inner;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author bpm
 * @since 2019-03-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/inner")
public class InnerController {

	private final SysDictService sysDictService;

	private final SysDictItemService sysDictItemService;



	/**
	 * 通过字典类型查找字典
	 * @param type 类型
	 * @return 同类型字典
	 */
	@GetMapping("/type/{type}")
	@Inner
	public R<List<SysDictItem>> getDictByType(@PathVariable String type) {
		return R.ok(Optional.ofNullable(sysDictItemService.list(Wrappers.<SysDictItem>query().lambda().eq(SysDictItem::getDictType, type))).orElse(new ArrayList<>()));
	}


}
